﻿using System;
using System.IO;
using System.Xml;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FUSE
{
    class ShipFile
    {
        //private ArrayList lineArray;
        public List<ShipData> loadedShips = new List<ShipData>();

        public ShipFile()
        {
            //lineArray = new ArrayList();
        }

        public void LoadShipFile()
        {
            string oldValue = "";
            string oldName = "";

            string name ="";
            int count = 0;
            int armor =0;
            int fuel = 0;
            int speed = 0;
            string texture ="";
            string iconTexture ="";
            string bigTexture = "";
            bool bName = false;
            bool bArmor = false;
            bool bFuel = false;
            bool bSpeed = false;
            bool bTexture = false;
            bool bIconTexture = false;
            bool bBigTexture = false;

            XmlTextReader reader = new XmlTextReader("../../../ships.xml");
            //XmlTextReader reader = new XmlTextReader("http://lampserv.no-ip.org/ships.xml");
            while (reader.Read())
            {
                if(reader.NodeType == XmlNodeType.Element)
                {
                    oldName = reader.Name;

                    //Console.WriteLine(">>>>>>>>>>>>>>>>>>>>>>>>");
                    if (reader.Name == "ship")
                    {
                        //Console.WriteLine("");
                    }
                    else
                    {
                       
                    }
                }
                
                if (reader.NodeType == XmlNodeType.Text)
                {
                    //Console.WriteLine(reader.Name);
                    //Console.WriteLine(reader.Value);
                    switch (oldName)
                    {


                        case "name":
                            if (reader.NodeType == XmlNodeType.Text)
                            {
                                name = reader.Value;
                                bName = true;
                            }
                            break;
                        case "armor":
                            if (reader.NodeType == XmlNodeType.Text)
                            {
                                armor = Int32.Parse(reader.Value);
                                bArmor = true;
                            }
                            break;
                        case "fuel":
                            if (reader.NodeType == XmlNodeType.Text)
                            {
                                fuel = Int32.Parse(reader.Value);
                                bFuel = true;

                            }
                            break;
                        case "speed":
                            if (reader.NodeType == XmlNodeType.Text)
                            {
                                speed = Int32.Parse(reader.Value);
                                bSpeed = true;
                            }
                            break;
                        case "texture":
                            if (reader.NodeType == XmlNodeType.Text)
                            {
                                texture = reader.Value;
                                bTexture = true;
                            }
                            break;
                        case "iconTexture":
                            if (reader.NodeType == XmlNodeType.Text)
                            {
                                iconTexture = reader.Value;
                                bIconTexture = true;
                            }
                            break;
                        case "bigTexture":
                            if (reader.NodeType == XmlNodeType.Text)
                            {
                                bigTexture = reader.Value;
                                bBigTexture = true;
                            }
                            break;
                        default:
                            break;
                    }
                }
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    //Console.WriteLine("<<<<<<<<<<<<<<<<<<<<<<<");
                    //Console.WriteLine(reader.Name);

                }



                

                if (bName != false && bArmor != false && bFuel != false && bSpeed != false && bTexture != false && bIconTexture != false && bBigTexture)
                {
                    //loadedShips.Add( new ShipData(name, armor, fuel, speed, texture ) );
                    bName = false;
                    bArmor = false;
                    bFuel = false;
                    bSpeed = false;
                    bTexture = false;
                    bIconTexture = false;
                    bBigTexture = false;

                    loadedShips.Add(new ShipData(name, count, armor, fuel, speed, texture, iconTexture, bigTexture));
                    count++;
                }
            }

            //Console.WriteLine("done parsing ships!");
            

        }

        public void ParseShips()
        {

        }

    }
}
